package com.itzgyw.example.config;

import com.itzgyw.cache.analysis.ResultTypeAnalysis;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.Page;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import java.util.List;

/**
 * @Auther: Mr. Zeng
 * @Date: 2020/8/20 21:47
 * @Description: 暂无描述
 */
@Configuration
public class BeanAutoConfiguration {
    @Bean
    public CacheManager cacheManager(RedisConnectionFactory factory) {
        RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration
                .defaultCacheConfig();
//                .entryTtl(Duration.ofMinutes(10)); // 设置过期时间

        return RedisCacheManager
                .builder(RedisCacheWriter.nonLockingRedisCacheWriter(factory))
                .cacheDefaults(defaultCacheConfig).build();
    }

    @Bean
    public IdEntityMetadataTrusteeship idEntityResultTrusteeship() {
        return new IdEntityMetadataTrusteeship();
    }

    @Bean
    public ResultTypeAnalysis<Page, List> resultTypeAnalysis() {
        return new PageableResultTypeAnalysis();
    }
}
